<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>React第二天(组件三大属性) | 小马の博客</title><meta name="keywords" content="React学习  组件三大属性"><meta name="author" content="Kun Kun"><meta name="copyright" content="Kun Kun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1、组件三大属性 1:state① 理解   state 是组件对象最重要的属性,值是对象(可以包含多个 key:value 的组合)  组件被称为状态机,通过更新组件的 state 来更新对应的页面显示(重新渲染组件)   ② 强烈注意   组件中的 render 方法中的 this 为组件实例对象   组件自定义方法中 this 为 undefined,如何解决?   a) 强制绑定 this">
<meta property="og:type" content="article">
<meta property="og:title" content="React第二天(组件三大属性)">
<meta property="og:url" content="https://ma_jinkun.gitee.io/2021/12/30/react/react-two/index.html">
<meta property="og:site_name" content="小马の博客">
<meta property="og:description" content="1、组件三大属性 1:state① 理解   state 是组件对象最重要的属性,值是对象(可以包含多个 key:value 的组合)  组件被称为状态机,通过更新组件的 state 来更新对应的页面显示(重新渲染组件)   ② 强烈注意   组件中的 render 方法中的 this 为组件实例对象   组件自定义方法中 this 为 undefined,如何解决?   a) 强制绑定 this">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg">
<meta property="article:published_time" content="2021-12-30T01:49:08.000Z">
<meta property="article:modified_time" content="2022-01-05T03:35:38.688Z">
<meta property="article:author" content="Kun Kun">
<meta property="article:tag" content="React学习  组件三大属性">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ma_jinkun.gitee.io/2021/12/30/react/react-two/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'React第二天(组件三大属性)',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-01-05 11:35:38'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiperstyle.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s2.loli.net/2021/12/28/uBIDZUEFrpsCvH7.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音樂</span></a></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw far fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s2.loli.net/2021/12/30/OjiswQgfeP3Jm4S.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小马の博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音樂</span></a></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw far fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">React第二天(组件三大属性)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-12-30T01:49:08.000Z" title="发表于 2021-12-30 09:49:08">2021-12-30</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-05T03:35:38.688Z" title="更新于 2022-01-05 11:35:38">2022-01-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/React-%E5%AD%A6%E4%B9%A0-%E7%BB%84%E4%BB%B6%E4%B8%89%E5%A4%A7%E5%B1%9E%E6%80%A7/">React  学习  组件三大属性</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="React第二天(组件三大属性)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="1、组件三大属性-1-state"><a href="#1、组件三大属性-1-state" class="headerlink" title="1、组件三大属性 1:state"></a>1、组件三大属性 1:state</h3><h5 id="①-理解"><a href="#①-理解" class="headerlink" title="① 理解"></a>① 理解</h5><blockquote>
<ol>
<li> state 是组件对象最重要的属性,值是对象(可以包含多个 key:value 的组合)</li>
<li> 组件被称为<code>状态机</code>,通过更新组件的 state 来更新对应的页面显示(重新渲染组件)</li>
</ol>
</blockquote>
<h5 id="②-强烈注意"><a href="#②-强烈注意" class="headerlink" title="② 强烈注意"></a>② 强烈注意</h5><blockquote>
<ol>
<li><p> 组件中的 render 方法中的 this 为组件实例对象</p>
</li>
<li><p> 组件自定义方法中 this 为 undefined,如何解决?</p>
</li>
</ol>
<p>a) 强制绑定 this:通过函数对象的 bind()</p>
<p>b) 箭头函数<code>推荐</code></p>
<ol start="3">
<li> 状态数据,不能直接修改或者更新</li>
</ol>
</blockquote>
<h5 id="③-代码示例"><a href="#③-代码示例" class="headerlink" title="③ 代码示例"></a>③ 代码示例</h5><h6 id="Ⅰ-正常的用函数对象的-bind"><a href="#Ⅰ-正常的用函数对象的-bind" class="headerlink" title="Ⅰ-正常的用函数对象的 bind()"></a>Ⅰ-正常的用函数对象的 bind()</h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建组件</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Weather</span> <span class="keyword">extends</span> <span class="title">React</span>.<span class="title">Component</span> </span>&#123;</span><br><span class="line">  <span class="comment">//构造器调用几次？ ———— 1次</span></span><br><span class="line">  <span class="function"><span class="title">constructor</span>(<span class="params">props</span>)</span> &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&quot;constructor&quot;</span>);</span><br><span class="line">    <span class="built_in">super</span>(props);</span><br><span class="line">    <span class="comment">//初始化状态</span></span><br><span class="line">    <span class="built_in">this</span>.state = &#123; <span class="attr">isHot</span>: <span class="literal">false</span>, <span class="attr">wind</span>: <span class="string">&quot;微风&quot;</span> &#125;;</span><br><span class="line">    <span class="comment">//解决changeWeather中this指向问题,也可以在调用出直接使用</span></span><br><span class="line">    <span class="built_in">this</span>.changeWeather = <span class="built_in">this</span>.changeWeather.bind(<span class="built_in">this</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">//render调用几次？ ———— 1+n次 1是初始化的那次 n是状态更新的次数</span></span><br><span class="line">  <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&quot;render&quot;</span>);</span><br><span class="line">    <span class="comment">//读取状态</span></span><br><span class="line">    <span class="keyword">const</span> &#123; isHot, wind &#125; = <span class="built_in">this</span>.state;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">      <span class="xml"><span class="tag">&lt;<span class="name">h1</span> <span class="attr">onClick</span>=<span class="string">&#123;this.changeWeather&#125;</span>&gt;</span></span></span><br><span class="line"><span class="xml">        今天天气很&#123;isHot ? &quot;炎热&quot; : &quot;凉爽&quot;&#125;，&#123;wind&#125;</span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">//changeWeather调用几次？ ———— 点几次调几次</span></span><br><span class="line">  <span class="function"><span class="title">changeWeather</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="comment">//changeWeather放在哪里？ ———— Weather的原型对象上，供实例使用</span></span><br><span class="line">    <span class="comment">//由于changeWeather是作为onClick的回调，所以不是通过实例调用的，是直接调用</span></span><br><span class="line">    <span class="comment">//类中的方法默认开启了局部的严格模式，所以changeWeather中的this为undefined</span></span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&quot;changeWeather&quot;</span>);</span><br><span class="line">    <span class="comment">//获取原来的isHot值</span></span><br><span class="line">    <span class="keyword">const</span> isHot = <span class="built_in">this</span>.state.isHot;</span><br><span class="line">    <span class="comment">//严重注意：状态必须通过setState进行更新,且更新是一种合并，不是替换。</span></span><br><span class="line">    <span class="built_in">this</span>.setState(&#123; <span class="attr">isHot</span>: !isHot &#125;);</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="built_in">this</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//严重注意：状态(state)不可直接更改，下面这行就是直接更改！！！</span></span><br><span class="line">    <span class="comment">//this.state.isHot = !isHot //这是错误的写法</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//2.渲染组件到页面</span></span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Weather</span> /&gt;</span></span>, <span class="built_in">document</span>.getElementById(<span class="string">&quot;test&quot;</span>));</span><br></pre></td></tr></table></figure>

<h6 id="Ⅱ-简写方式-赋值语句的形式-箭头函数"><a href="#Ⅱ-简写方式-赋值语句的形式-箭头函数" class="headerlink" title="Ⅱ-简写方式:赋值语句的形式+箭头函数"></a>Ⅱ-简写方式:赋值语句的形式+箭头函数</h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建组件</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Weather</span> <span class="keyword">extends</span> <span class="title">React</span>.<span class="title">Component</span> </span>&#123;</span><br><span class="line">  <span class="comment">//初始化状态</span></span><br><span class="line">  state = &#123; <span class="attr">isHot</span>: <span class="literal">false</span>, <span class="attr">wind</span>: <span class="string">&quot;微风&quot;</span> &#125;;</span><br><span class="line">  <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> &#123; isHot, wind &#125; = <span class="built_in">this</span>.state;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">      <span class="xml"><span class="tag">&lt;<span class="name">h1</span> <span class="attr">onClick</span>=<span class="string">&#123;this.changeWeather&#125;</span>&gt;</span></span></span><br><span class="line"><span class="xml">        今天天气很&#123;isHot ? &quot;炎热&quot; : &quot;凉爽&quot;&#125;，&#123;wind&#125;</span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">//自定义方法————要用赋值语句的形式+箭头函数</span></span><br><span class="line">  changeWeather = <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">const</span> isHot = <span class="built_in">this</span>.state.isHot;</span><br><span class="line">    <span class="built_in">this</span>.setState(&#123; <span class="attr">isHot</span>: !isHot &#125;);</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//2.渲染组件到页面</span></span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Weather</span> /&gt;</span></span>, <span class="built_in">document</span>.getElementById(<span class="string">&quot;test&quot;</span>));</span><br></pre></td></tr></table></figure>

<h3 id="2、组件三大属性-2-props"><a href="#2、组件三大属性-2-props" class="headerlink" title="2、组件三大属性 2:props"></a>2、组件三大属性 2:props</h3><h5 id="①-理解-1"><a href="#①-理解-1" class="headerlink" title="① 理解"></a>① 理解</h5><blockquote>
<ol>
<li> 每个组件对象都会有 props(properties 的简写)属性</li>
<li> 组件标签的所有属性都保存在 props 中</li>
</ol>
</blockquote>
<h5 id="②-作用"><a href="#②-作用" class="headerlink" title="② 作用"></a>② 作用</h5><blockquote>
<ol>
<li> 通过标签属性从组件外向组件内传递变化的数据</li>
<li> 注意:组件内部不要修改 props 数据</li>
</ol>
</blockquote>
<h5 id="③-代码示例-1"><a href="#③-代码示例-1" class="headerlink" title="③ 代码示例:"></a>③ 代码示例:</h5><h6 id="Ⅰ-类组件使用-props"><a href="#Ⅰ-类组件使用-props" class="headerlink" title="Ⅰ-类组件使用 props"></a>Ⅰ-类组件使用 props</h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//创建组件</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span> <span class="keyword">extends</span> <span class="title">React</span>.<span class="title">Component</span> </span>&#123;</span><br><span class="line">  <span class="function"><span class="title">render</span>(<span class="params"></span>)</span> &#123;</span><br><span class="line">    <span class="comment">// console.log(this);</span></span><br><span class="line">    <span class="keyword">const</span> &#123; name, age, sex &#125; = <span class="built_in">this</span>.props;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">      <span class="xml"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">li</span>&gt;</span>姓名：&#123;name&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">li</span>&gt;</span>性别：&#123;sex&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">li</span>&gt;</span>年龄：&#123;age + 1&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"><span class="xml">      <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span></span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//渲染组件到页面</span></span><br><span class="line">ReactDOM.render(</span><br><span class="line">  <span class="xml"><span class="tag">&lt;<span class="name">Person</span> <span class="attr">name</span>=<span class="string">&quot;jerry&quot;</span> <span class="attr">age</span>=<span class="string">&#123;19&#125;</span> <span class="attr">sex</span>=<span class="string">&quot;男&quot;</span> /&gt;</span></span>,</span><br><span class="line">  <span class="built_in">document</span>.getElementById(<span class="string">&quot;test1&quot;</span>)</span><br><span class="line">);</span><br><span class="line">ReactDOM.render(</span><br><span class="line">  <span class="xml"><span class="tag">&lt;<span class="name">Person</span> <span class="attr">name</span>=<span class="string">&quot;tom&quot;</span> <span class="attr">age</span>=<span class="string">&#123;18&#125;</span> <span class="attr">sex</span>=<span class="string">&quot;女&quot;</span> /&gt;</span></span>,</span><br><span class="line">  <span class="built_in">document</span>.getElementById(<span class="string">&quot;test2&quot;</span>)</span><br><span class="line">);</span><br><span class="line"><span class="keyword">const</span> p = &#123; <span class="attr">name</span>: <span class="string">&quot;老刘&quot;</span>, <span class="attr">age</span>: <span class="number">18</span>, <span class="attr">sex</span>: <span class="string">&quot;女&quot;</span> &#125;;</span><br><span class="line"><span class="comment">// console.log(&#x27;@&#x27;,...p);</span></span><br><span class="line"><span class="comment">// ReactDOM.render(&lt;Person name=&#123;p.name&#125; age=&#123;p.age&#125; sex=&#123;p.sex&#125;/&gt;,document.getElementById(&#x27;test3&#x27;))</span></span><br><span class="line"><span class="comment">//此处使用赋值解构方式,使得代码更简洁</span></span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Person</span> &#123;<span class="attr">...p</span>&#125; /&gt;</span></span>, <span class="built_in">document</span>.getElementById(<span class="string">&quot;test3&quot;</span>));</span><br></pre></td></tr></table></figure>

<h3 id="3、组件三大属性-3-refs"><a href="#3、组件三大属性-3-refs" class="headerlink" title="3、组件三大属性 3:refs"></a>3、组件三大属性 3:refs</h3><h5 id="①-理解-2"><a href="#①-理解-2" class="headerlink" title="① 理解"></a>① 理解</h5><blockquote>
<p>组件内的标签可以定义 ref 来标识自己</p>
</blockquote>
<h5 id="②-代码示例"><a href="#②-代码示例" class="headerlink" title="② 代码示例:"></a>② 代码示例:</h5><h6 id="1、字符串形式的-ref-不推荐-将被淘汰"><a href="#1、字符串形式的-ref-不推荐-将被淘汰" class="headerlink" title="1、字符串形式的 ref(不推荐,将被淘汰)"></a>1、字符串形式的 ref(<code>不推荐,将被淘汰</code>)</h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//展示左侧输入框的数据</span></span><br><span class="line">	showData = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">		<span class="keyword">const</span> &#123;input1&#125; = <span class="built_in">this</span>.refs</span><br><span class="line">		alert(input1.value)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//展示右侧输入框的数据</span></span><br><span class="line">	showData2 = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">		<span class="keyword">const</span> &#123;input2&#125; = <span class="built_in">this</span>.refs</span><br><span class="line">		alert(input2.value)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="title">render</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="keyword">return</span>(</span><br><span class="line">			<span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&quot;input1&quot;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;点击按钮提示数据&quot;</span>/&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">button</span> <span class="attr">onClick</span>=<span class="string">&#123;this.showData&#125;</span>&gt;</span>点我提示左侧的数据<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&quot;input2&quot;</span> <span class="attr">onBlur</span>=<span class="string">&#123;this.showData2&#125;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;失去焦点提示数据&quot;</span>/&gt;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">		)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="2、回调形式的-ref"><a href="#2、回调形式的-ref" class="headerlink" title="2、回调形式的 ref"></a>2、回调形式的 ref</h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**下面的this指的是组件实例,我直接this.input1 = c 意思是给实例上的input1赋值,之后直接通过调用打印得到*/</span></span><br><span class="line"><span class="comment">//展示左侧输入框的数据</span></span><br><span class="line">	showData = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">		<span class="keyword">const</span> &#123;input1&#125; = <span class="built_in">this</span></span><br><span class="line">		alert(input1.value)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">//展示右侧输入框的数据</span></span><br><span class="line">	showData2 = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">		<span class="keyword">const</span> &#123;input2&#125; = <span class="built_in">this</span></span><br><span class="line">		alert(input2.value)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="title">render</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="keyword">return</span>(</span><br><span class="line">			<span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&#123;c</span> =&gt;</span> this.input1 = c &#125; type=&quot;text&quot; placeholder=&quot;点击按钮提示数据&quot;/&gt;<span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">button</span> <span class="attr">onClick</span>=<span class="string">&#123;this.showData&#125;</span>&gt;</span>点我提示左侧的数据<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">input</span> <span class="attr">onBlur</span>=<span class="string">&#123;this.showData2&#125;</span> <span class="attr">ref</span>=<span class="string">&#123;c</span> =&gt;</span> this.input2 = c &#125; type=&quot;text&quot; placeholder=&quot;失去焦点提示数据&quot;/&gt;<span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">		)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h6 id="3、createRef-创建-ref-容器最推荐的"><a href="#3、createRef-创建-ref-容器最推荐的" class="headerlink" title="3、createRef 创建 ref 容器最推荐的"></a>3、createRef 创建 ref 容器<code>最推荐的</code></h6><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*React.createRef调用后可以返回一个容器，该容器可以存储被ref所标识的节点,该容器是“专人专用”的*/</span></span><br><span class="line">myRef = React.createRef()</span><br><span class="line">myRef2 = React.createRef()</span><br><span class="line"><span class="comment">//展示左侧输入框的数据</span></span><br><span class="line">showData = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">	alert(<span class="built_in">this</span>.myRef.current.value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//展示右侧输入框的数据</span></span><br><span class="line">showData2 = <span class="function">()=&gt;</span>&#123;</span><br><span class="line">	alert(<span class="built_in">this</span>.myRef2.current.value);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="title">render</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">return</span>(</span><br><span class="line">		<span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&#123;this.myRef&#125;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;点击按钮提示数据&quot;</span>/&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;<span class="name">button</span> <span class="attr">onClick</span>=<span class="string">&#123;this.showData&#125;</span>&gt;</span>点我提示左侧的数据<span class="tag">&lt;/<span class="name">button</span>&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;<span class="name">input</span> <span class="attr">onBlur</span>=<span class="string">&#123;this.showData2&#125;</span> <span class="attr">ref</span>=<span class="string">&#123;this.myRef2&#125;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">placeholder</span>=<span class="string">&quot;失去焦点提示数据&quot;</span>/&gt;</span><span class="symbol">&amp;nbsp;</span></span></span><br><span class="line"><span class="xml">		<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">	)</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4、事件处理与收集表单数据"><a href="#4、事件处理与收集表单数据" class="headerlink" title="4、事件处理与收集表单数据"></a>4、事件处理与收集表单数据</h3><h4 id="Ⅰ-事件处理"><a href="#Ⅰ-事件处理" class="headerlink" title="Ⅰ-事件处理"></a>Ⅰ-事件处理</h4><blockquote>
<ol>
<li> 通过 onXxx 属性指定事件处理函数(注意大小写)</li>
</ol>
<p>a)React 使用的是自定义(合成事件,而不是使用的原生 DOM 事件) —-为了更好的兼容性</p>
<p>b)React 中的事件是通过事件委托的方式处理的(委托给组件最外层的元素)—-为了更高效</p>
<ol start="2">
<li> 通过 event.target 得到发生事件的 DOM 元素对象 —–不要过度使用 ref</li>
</ol>
</blockquote>
<h4 id="Ⅱ-表单组件的分类"><a href="#Ⅱ-表单组件的分类" class="headerlink" title="Ⅱ-表单组件的分类"></a>Ⅱ-表单组件的分类</h4><blockquote>
<p>就形式上来说，**<code>受控组件</code>就是为某个 form 表单组件添加<code>value</code>属性；<code>非受控组件</code>就是没有添加<code>value</code>属性的组件**</p>
</blockquote>
<h5 id="1、受控组件"><a href="#1、受控组件" class="headerlink" title="1、受控组件"></a>1、受控组件</h5><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">state = &#123;<span class="comment">//初始化状态</span></span><br><span class="line">	<span class="attr">username</span>:<span class="string">&#x27;&#x27;</span>, <span class="comment">//用户名</span></span><br><span class="line">	<span class="attr">password</span>:<span class="string">&#x27;&#x27;</span> <span class="comment">//密码</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//保存用户名到状态中</span></span><br><span class="line">saveUsername = <span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">	<span class="built_in">this</span>.setState(&#123;<span class="attr">username</span>:event.target.value&#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//保存密码到状态中</span></span><br><span class="line">savePassword = <span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">	<span class="built_in">this</span>.setState(&#123;<span class="attr">password</span>:event.target.value&#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//表单提交的回调</span></span><br><span class="line">handleSubmit = <span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">	event.preventDefault() <span class="comment">//阻止表单提交</span></span><br><span class="line">	<span class="keyword">const</span> &#123;username,password&#125; = <span class="built_in">this</span>.state</span><br><span class="line">	alert(<span class="string">`你输入的用户名是：<span class="subst">$&#123;username&#125;</span>,你输入的密码是：<span class="subst">$&#123;password&#125;</span>`</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="title">render</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">return</span>(</span><br><span class="line">		<span class="xml"><span class="tag">&lt;<span class="name">form</span> <span class="attr">onSubmit</span>=<span class="string">&#123;this.handleSubmit&#125;</span>&gt;</span></span></span><br><span class="line"><span class="xml">			用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">onChange</span>=<span class="string">&#123;this.saveUsername&#125;</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span>/&gt;</span></span></span><br><span class="line"><span class="xml">			密码：<span class="tag">&lt;<span class="name">input</span> <span class="attr">onChange</span>=<span class="string">&#123;this.savePassword&#125;</span> <span class="attr">type</span>=<span class="string">&quot;password&quot;</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span>/&gt;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;<span class="name">button</span>&gt;</span>登录<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line"><span class="xml">		<span class="tag">&lt;/<span class="name">form</span>&gt;</span></span></span><br><span class="line">	)</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h5 id="2、非受控组件"><a href="#2、非受控组件" class="headerlink" title="2、非受控组件"></a>2、非受控组件</h5><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">handleSubmit = <span class="function">(<span class="params">event</span>)=&gt;</span>&#123;</span><br><span class="line">		event.preventDefault() <span class="comment">//阻止表单提交</span></span><br><span class="line">		<span class="keyword">const</span> &#123;username,password&#125; = <span class="built_in">this</span></span><br><span class="line">		alert(<span class="string">`你输入的用户名是：<span class="subst">$&#123;username.value&#125;</span>,你输入的密码是：<span class="subst">$&#123;password.value&#125;</span>`</span>)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="function"><span class="title">render</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">		<span class="keyword">return</span>(</span><br><span class="line">			<span class="xml"><span class="tag">&lt;<span class="name">form</span> <span class="attr">onSubmit</span>=<span class="string">&#123;this.handleSubmit&#125;</span>&gt;</span></span></span><br><span class="line"><span class="xml">				用户名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&#123;c</span> =&gt;</span> this.username = c&#125; type=&quot;text&quot; name=&quot;username&quot;/&gt;</span></span><br><span class="line"><span class="xml">				密码：<span class="tag">&lt;<span class="name">input</span> <span class="attr">ref</span>=<span class="string">&#123;c</span> =&gt;</span> this.password = c&#125; type=&quot;password&quot; name=&quot;password&quot;/&gt;</span></span><br><span class="line"><span class="xml">				<span class="tag">&lt;<span class="name">button</span>&gt;</span>登录<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line"><span class="xml">			<span class="tag">&lt;/<span class="name">form</span>&gt;</span></span></span><br><span class="line">		)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="5、高阶函数与函数柯里化"><a href="#5、高阶函数与函数柯里化" class="headerlink" title="5、高阶函数与函数柯里化"></a>5、高阶函数与函数柯里化</h3><h5 id="①-高阶函数"><a href="#①-高阶函数" class="headerlink" title="① 高阶函数:"></a>① 高阶函数:</h5><blockquote>
<p>如果一个函数符合下面两个规范中的任何一个,那该函数就是高阶函数</p>
<ol>
<li> 若 A 函数,接受的参数是一个函数,那么 A 就可以称之为高阶函数</li>
<li> 若 A 函数,调用的返回值依然是一个函数,那么 A 就可以称之为高阶函数</li>
</ol>
<p>常见的高阶函数有:Promise、setTimeout、arr.map()等等</p>
</blockquote>
<h5 id="②-函数的柯里化"><a href="#②-函数的柯里化" class="headerlink" title="② 函数的柯里化"></a>② 函数的柯里化</h5><blockquote>
<p>通过函数调用继续返回函数的方式,实现对此接受参数最后统一处理的函数编码形式</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">sum</span>(<span class="params">a</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="function">(<span class="params">b</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="function">(<span class="params">c</span>) =&gt;</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> a + b + c;</span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</blockquote>
<h5 id="③-不用函数柯里化实现事件的绑定"><a href="#③-不用函数柯里化实现事件的绑定" class="headerlink" title="③ 不用函数柯里化实现事件的绑定"></a>③ 不用函数柯里化实现事件的绑定</h5><blockquote>
<p>直接使用回调函数,因为他本身就是以一个函数为返回值</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;input</span><br><span class="line">  onChange=&#123;<span class="function">(<span class="params">event</span>) =&gt;</span> <span class="built_in">this</span>.saveFormData(<span class="string">&quot;username&quot;</span>, event)&#125;</span><br><span class="line">  type=<span class="string">&quot;text&quot;</span></span><br><span class="line">  name=<span class="string">&quot;username&quot;</span></span><br><span class="line">/&gt;</span><br></pre></td></tr></table></figure>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Kun Kun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://ma_jinkun.gitee.io/2021/12/30/react/react-two/">https://ma_jinkun.gitee.io/2021/12/30/react/react-two/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ma_jinkun.gitee.io" target="_blank">小马の博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/React%E5%AD%A6%E4%B9%A0-%E7%BB%84%E4%BB%B6%E4%B8%89%E5%A4%A7%E5%B1%9E%E6%80%A7/">React学习  组件三大属性</a></div><div class="post_share"><div class="social-share" data-image="[&quot;https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg&quot;]" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/12/30/react/react-cycle/"><img class="prev-cover" src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">React(生命周期,脚手架)</div></div></a></div><div class="next-post pull-right"><a href="/2021/12/29/react/React-one/"><img class="next-cover" src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">React学习</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s2.loli.net/2021/12/28/uBIDZUEFrpsCvH7.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Kun Kun</div><div class="author-info__description">嘘,别看,眼睛会疼！</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:2583931485@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="qq:2583931485" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">基于Hexo 主题butterfly 开发的</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E7%BB%84%E4%BB%B6%E4%B8%89%E5%A4%A7%E5%B1%9E%E6%80%A7-1-state"><span class="toc-number">1.</span> <span class="toc-text">1、组件三大属性 1:state</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E7%90%86%E8%A7%A3"><span class="toc-number">1.0.1.</span> <span class="toc-text">① 理解</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E5%BC%BA%E7%83%88%E6%B3%A8%E6%84%8F"><span class="toc-number">1.0.2.</span> <span class="toc-text">② 强烈注意</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A2-%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B"><span class="toc-number">1.0.3.</span> <span class="toc-text">③ 代码示例</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%85%A0-%E6%AD%A3%E5%B8%B8%E7%9A%84%E7%94%A8%E5%87%BD%E6%95%B0%E5%AF%B9%E8%B1%A1%E7%9A%84-bind"><span class="toc-number">1.0.3.1.</span> <span class="toc-text">Ⅰ-正常的用函数对象的 bind()</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%85%A1-%E7%AE%80%E5%86%99%E6%96%B9%E5%BC%8F-%E8%B5%8B%E5%80%BC%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%BD%A2%E5%BC%8F-%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0"><span class="toc-number">1.0.3.2.</span> <span class="toc-text">Ⅱ-简写方式:赋值语句的形式+箭头函数</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E7%BB%84%E4%BB%B6%E4%B8%89%E5%A4%A7%E5%B1%9E%E6%80%A7-2-props"><span class="toc-number">2.</span> <span class="toc-text">2、组件三大属性 2:props</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E7%90%86%E8%A7%A3-1"><span class="toc-number">2.0.1.</span> <span class="toc-text">① 理解</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E4%BD%9C%E7%94%A8"><span class="toc-number">2.0.2.</span> <span class="toc-text">② 作用</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A2-%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B-1"><span class="toc-number">2.0.3.</span> <span class="toc-text">③ 代码示例:</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E2%85%A0-%E7%B1%BB%E7%BB%84%E4%BB%B6%E4%BD%BF%E7%94%A8-props"><span class="toc-number">2.0.3.1.</span> <span class="toc-text">Ⅰ-类组件使用 props</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E7%BB%84%E4%BB%B6%E4%B8%89%E5%A4%A7%E5%B1%9E%E6%80%A7-3-refs"><span class="toc-number">3.</span> <span class="toc-text">3、组件三大属性 3:refs</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E7%90%86%E8%A7%A3-2"><span class="toc-number">3.0.1.</span> <span class="toc-text">① 理解</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E4%BB%A3%E7%A0%81%E7%A4%BA%E4%BE%8B"><span class="toc-number">3.0.2.</span> <span class="toc-text">② 代码示例:</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%BD%A2%E5%BC%8F%E7%9A%84-ref-%E4%B8%8D%E6%8E%A8%E8%8D%90-%E5%B0%86%E8%A2%AB%E6%B7%98%E6%B1%B0"><span class="toc-number">3.0.2.1.</span> <span class="toc-text">1、字符串形式的 ref(不推荐,将被淘汰)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2%E3%80%81%E5%9B%9E%E8%B0%83%E5%BD%A2%E5%BC%8F%E7%9A%84-ref"><span class="toc-number">3.0.2.2.</span> <span class="toc-text">2、回调形式的 ref</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3%E3%80%81createRef-%E5%88%9B%E5%BB%BA-ref-%E5%AE%B9%E5%99%A8%E6%9C%80%E6%8E%A8%E8%8D%90%E7%9A%84"><span class="toc-number">3.0.2.3.</span> <span class="toc-text">3、createRef 创建 ref 容器最推荐的</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E4%B8%8E%E6%94%B6%E9%9B%86%E8%A1%A8%E5%8D%95%E6%95%B0%E6%8D%AE"><span class="toc-number">4.</span> <span class="toc-text">4、事件处理与收集表单数据</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E2%85%A0-%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86"><span class="toc-number">4.1.</span> <span class="toc-text">Ⅰ-事件处理</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E2%85%A1-%E8%A1%A8%E5%8D%95%E7%BB%84%E4%BB%B6%E7%9A%84%E5%88%86%E7%B1%BB"><span class="toc-number">4.2.</span> <span class="toc-text">Ⅱ-表单组件的分类</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1%E3%80%81%E5%8F%97%E6%8E%A7%E7%BB%84%E4%BB%B6"><span class="toc-number">4.2.1.</span> <span class="toc-text">1、受控组件</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2%E3%80%81%E9%9D%9E%E5%8F%97%E6%8E%A7%E7%BB%84%E4%BB%B6"><span class="toc-number">4.2.2.</span> <span class="toc-text">2、非受控组件</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5%E3%80%81%E9%AB%98%E9%98%B6%E5%87%BD%E6%95%B0%E4%B8%8E%E5%87%BD%E6%95%B0%E6%9F%AF%E9%87%8C%E5%8C%96"><span class="toc-number">5.</span> <span class="toc-text">5、高阶函数与函数柯里化</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E9%AB%98%E9%98%B6%E5%87%BD%E6%95%B0"><span class="toc-number">5.0.1.</span> <span class="toc-text">① 高阶函数:</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E5%87%BD%E6%95%B0%E7%9A%84%E6%9F%AF%E9%87%8C%E5%8C%96"><span class="toc-number">5.0.2.</span> <span class="toc-text">② 函数的柯里化</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A2-%E4%B8%8D%E7%94%A8%E5%87%BD%E6%95%B0%E6%9F%AF%E9%87%8C%E5%8C%96%E5%AE%9E%E7%8E%B0%E4%BA%8B%E4%BB%B6%E7%9A%84%E7%BB%91%E5%AE%9A"><span class="toc-number">5.0.3.</span> <span class="toc-text">③ 不用函数柯里化实现事件的绑定</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/01/04/react-ly/" title="React路由"><img src="[&quot;https://image-tupss.test.upcdn.net/baner.png&quot;]" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React路由"/></a><div class="content"><a class="title" href="/2022/01/04/react-ly/" title="React路由">React路由</a><time datetime="2022-01-04T06:28:11.000Z" title="发表于 2022-01-04 14:28:11">2022-01-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-proxy/" title="React 配置代理"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React 配置代理"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-proxy/" title="React 配置代理">React 配置代理</a><time datetime="2021-12-30T02:14:13.000Z" title="发表于 2021-12-30 10:14:13">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-cycle/" title="React(生命周期,脚手架)"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React(生命周期,脚手架)"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-cycle/" title="React(生命周期,脚手架)">React(生命周期,脚手架)</a><time datetime="2021-12-30T01:58:45.000Z" title="发表于 2021-12-30 09:58:45">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-two/" title="React第二天(组件三大属性)"><img src="[&quot;https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg&quot;]" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React第二天(组件三大属性)"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-two/" title="React第二天(组件三大属性)">React第二天(组件三大属性)</a><time datetime="2021-12-30T01:49:08.000Z" title="发表于 2021-12-30 09:49:08">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/29/react/React-one/" title="React学习"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React学习"/></a><div class="content"><a class="title" href="/2021/12/29/react/React-one/" title="React学习">React学习</a><time datetime="2021-12-29T09:24:15.000Z" title="发表于 2021-12-29 17:24:15">2021-12-29</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Kun Kun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function history_calendar_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div>';
                console.log('已挂载history_calendar')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            history_calendar_injector_config()
        } </script><script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script> <script data-pjax>if(document.getElementById('recent-posts') && location.pathname =='/'){
    
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-28</span><a class="blog-slider__title" href="2021/12/28/My-First-Artical/">第一次测试文档</a><div class="blog-slider__text">简单好用的 hexo 博客文章置顶插件！</div><a class="blog-slider__button" href="2021/12/28/My-First-Artical/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://image-tupss.test.upcdn.net/baner.png" alt="https://image-tupss.test.upcdn.net/baner.png"/></div><div class="blog-slider__content"><span class="blog-slider__code">2022-01-04</span><a class="blog-slider__title" href="2022/01/04/react-ly/">React路由</a><div class="blog-slider__text">React路由！</div><a class="blog-slider__button" href="2022/01/04/react-ly/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-cycle/">React(生命周期,脚手架)</a><div class="blog-slider__text">生命周期 脚手架！</div><a class="blog-slider__button" href="2021/12/30/react/react-cycle/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-proxy/">React 配置代理</a><div class="blog-slider__text">配置代理！</div><a class="blog-slider__button" href="2021/12/30/react/react-proxy/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg" alt="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-two/">React第二天(组件三大属性)</a><div class="blog-slider__text">第二天！</div><a class="blog-slider__button" href="2021/12/30/react/react-two/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-29</span><a class="blog-slider__title" href="2021/12/29/react/React-one/">React学习</a><div class="blog-slider__text">第一天！</div><a class="blog-slider__button" href="2021/12/29/react/React-one/">详情</a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载swiper')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.js"></script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper@0.18/swiper/swiperindex.js"></script>
<style></style><!-- hexo injector body_end end --></body></html>